Skip to content

fix: Accept single words as valid hostnames #3591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop-2.0.0
Choose a base branch
from

Conversation

simon-lemay-unity
Copy link
Contributor

Purpose of this PR

The regex we used to validate hostnames did not accept single words as valid hostnames. But single words can be valid hostnames. The most common is of course "localhost" but one can edit one's hosts file to define any word as something the local resolver will resolve to an IP address.

This PR addresses this by removing any validation of the provided hostname. We could modify the validity check to accept single words too, but the regex is pretty indigestible already and it's simpler to just let the resolver fail if the user provided garbage. UTP will signal this through a disconnection event with an appropriate reason (which we'll be able to map to a nice error message once this PR lands).

While I was at it, I also made a few cleanups and improvements:

  • Removed the UTP_TRANSPORT_2_4_ABOVE define. NGO depends on UTP 2.4.0 so it can be safely assumed that users will have it installed. No need to conditionally compile the code that depends on it.
  • Added a test that establishes a connection using hostname resolution.
  • Simplified the logic around connections and avoid bypassing the Connect method when connecting to a hostname.
  • Deprecated ConnectionAddressData.ServerEndPoint. We don't use it anymore, it doesn't work with hostnames, and it's not providing any value over just calling NetworkEndpoint.Parse. And worst of all: its capitalization of "endpoint" doesn't match what we use elsewhere.
  • Modified the listen address logic so that if a domain name is used, by default if remote connections are allowed we will listen on :: (the IPv6 "any" address) instead of 0.0.0.0. This can still be overridden using SetConnectionData. The reason for this change is that the resolver in UTP prioritizes IPv6 addresses over IPv4. So if we listen on IPv4 by default, we're likely to get issues if the resolver then ends up with an IPv6 address. In current versions of UTP for instance, this causes errors on Windows (a fix is on the way). I'm looking into changing the behavior of the resolver to prefer IPv4, but that's an engine change so might take a while to land. In the meantime defaulting to IPv6 seems like the best approach.

Changelog

  • Fixed: Fixed an issue where UnityTransport would not accept single words as valid hostnames (notably "localhost").
  • Changed: Marked UnityTransport.ConnectionAddressData.ServerEndPoint as obsolete. It can't work when using hostnames as the server address, and its functionality can easily be replicated using NetworkEndpoint.Parse.

Documentation

No documentation changes or additions were necessary.

Testing & QA

Tested with manual and automated tests.

Backport

Hostname resolution is only supported in UTP 2.4+ and Unity 6.1+, so no backport necessary.

@simon-lemay-unity simon-lemay-unity changed the title fix: Accept singles words as valid hostnames fix: Accept single words as valid hostnames Aug 11, 2025
@@ -7,7 +7,7 @@

using System;
using System.Collections.Generic;
#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
#if HOSTNAME_RESOLUTION_AVAILABLE
using System.Text.RegularExpressions;
Copy link
Collaborator

@michalChrobot michalChrobot Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests failed because initial standards check failed with an error about this line error IDE0005: Using directive is unnecessary. so I guess that this can be completely removed (worth confirming so I just left the comment instead of removing it already)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other then that it's a really nice PR and description!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for having a look at the failure! We indeed don't need to use regexes anymore.

Copy link
Collaborator

@michalChrobot michalChrobot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side, I would still wait for Noel or Emma to also approve/comment

@michalChrobot
Copy link
Collaborator

michalChrobot commented Aug 13, 2025

FYI the CMB Service Test failure is a know issue that Noel is addressing

*update, it was fixed and I merged latest content from develop-2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants